﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoursePack;

namespace TheSchedulator
{
    public static class RateMyProfessor
    {

        public static RateMyProfessorResponse GetProfessorRating(Course _Course)
        {

            HttpRequest myrequest = new HttpRequest(HttpMethod.POST, new Uri("http://www.ratemyprofessors.com/solr/interim.jsp?select?facet=true&q=" 
                + _Course.Lecture.ProfessorII 
                + "&facet.field=schoolname_s&facet.field=teacherdepartment_s&facet.field=schoolcountry_s&facet.field=schoolstate_s&facet.limit=2&rows=20&facet.mincount=1&json.nl=map&fq=content_type_s%3ATEACHER&wt=json"));
            
            myrequest.SendRequest("");
            string lol = myrequest.ResponseStream;

            RateMyProfessorResponse myDeserializedObjList = (RateMyProfessorResponse)Newtonsoft.Json.JsonConvert.DeserializeObject(lol, typeof(RateMyProfessorResponse));

            return myDeserializedObjList;
        }

    }


    public class RateMyProfessorResponse
    {
        public object responseHeader;
        public object facet;
        public Response response;

        public string Clarity
        {
            get { return response.docs[0].averageclarityscore_rf; }
        }

        public string Helpfulness
        {
            get { return response.docs[0].averagehelpfulscore_rf; }
        }
        
        public string Overall
        {
            get { return response.docs[0].averageratingscore_rf; }
        }
        
        public string Easiness
        {
            get { return response.docs[0].averageeasyscore_rf; }
        }

        public bool IsRatingAvailable
        {
            get { return (int.Parse(response.numFound) > 0); }
        }

        public class Response
        {
            public string numFound { get; set; }
            public string start { get; set; }
            public Docs[] docs { get; set; }
        }

        public class Docs
        {
            public string teacherdepartment_s { get; set; }
            public string schoolid_s { get; set; }
            public string schoolname_s { get; set; }
            public string schoolstate_s { get; set; }
            public string status_i { get; set; }
            public string schoolcity_s { get; set; }
            public string teacherfirstname_t { get; set; }
            public string averagehotscore_rf { get; set; }
            public string pk_id { get; set; }
            public string id { get; set; }
            public string content_type_s { get; set; }
            public string schoolwebpage_s { get; set; }
            public string schoolcountry_s { get; set; }

            public string averageclarityscore_rf { get; set; }
            public string averageeasyscore_rf { get; set; }
            public string teacherfullname_s { get; set; }

            public string teacherlastname_t { get; set; }
            public string averageratingscore_rf { get; set; }
            public string averagehelpfulscore_rf { get; set; }
        }
    }


}
